package org.fin.framework.ioc.factory;

public abstract class AbstractApplicationContext implements BeanFactory {

  private DefaultBeanFactory beanFactory;

  protected void init() {
    // 初始化BeanFactory
    initailizeBeanFactory();

    // 实例化（注册）BeanInterceptor
    beanFactory.registerBeanInterceptors();

    // 实例化bean
    beanFactory.instantiateBeans();

  }


  protected void initailizeBeanFactory() {
    beanFactory = new DefaultBeanFactory();

    // 读取bean信息
    loadBeanDefinitions();
  }


  @Override
  public Object getBean(String id) {
    return beanFactory.getBean(id);
  }

  @Override
  public <T> T getBean(String id, Class<T> type) {
    return beanFactory.getBean(id, type);
  }

  @Override
  public <T> T getBean(Class<T> type) {
    return beanFactory.getBean(type);
  }

  public DefaultBeanFactory getBeanFactory() {
    return beanFactory;
  }

  protected abstract void loadBeanDefinitions();
}
